// range heap example
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool cmp(int a, int b)
{
    return a>b;
}

int main () {
    int myints[] = {10,20,30,5,15};
    vector<int> v(myints,myints+5);
    vector<int>::iterator it;
 
    make_heap (v.begin(),v.end(),cmp);
    cout << "initial max heap   : " << v.front() << endl;

    pop_heap (v.begin(),v.end(),cmp); 
    v.pop_back();
    cout << "max heap after pop : " << v.front() << endl;

    v.push_back(1); 
    push_heap (v.begin(),v.end(),cmp);
    cout << "max heap after push: " << v.front() << endl;

    sort_heap (v.begin(),v.end(),cmp);
    
    cout << "final sorted range :";
    for (unsigned i=0; i<v.size(); i++)
        cout << " " << v[i];
    cout << endl;
    return 0;
}
